/**
  * Created by liyun on 2017/2/13.
  * Author: yunpengl@genice.cc
  * Date: 2017/2/13
  * Time: 15:08
  * 
  */
'use strict';
const log = require('log4js').getLogger("qn");
const settings = require('../config/settings'),
    qiniu_conf = settings.qiniu_conf;
const qiniu = require('qiniu');
qiniu.conf.ACCESS_KEY = qiniu_conf.access_key;
qiniu.conf.SECRET_KEY = qiniu_conf.secret_key;

const uptoken = new qiniu.rs.PutPolicy(qiniu_conf.bucket_name);

/*
 * 获取七牛上传文件token
 */
exports.token = function (req, res) {
    const type = req.params.type;
    const token = uptoken.token();
    const imgName = type  + '/' + Date.now() + '.jpg';
    log.debug(imgName);
    const key =  qiniu.util.urlsafeBase64Encode(imgName);
    res.send({
        token: token,
        key: key
    });

};
